Skip to content

fix(sandbox): point the default image at the packaged Dockerfile - #1059

Open
morinokami wants to merge 3 commits into
voidzero-dev:mainfrom
morinokami:fix/sandbox-default-image
Open

morinokami wants to merge 3 commits into
voidzero-dev:mainfrom
morinokami:fix/sandbox-default-image

Conversation

@morinokami

Copy link
Copy Markdown
Collaborator

The Sandboxes guide starts with a route that runs a command, and says that importing from void/sandbox enables the required resources:

// routes/api/sandbox.ts
import { defineHandler } from 'void';
import { getSandbox } from 'void/sandbox';

export const POST = defineHandler(async (c) => {
  const sandbox = await getSandbox('default');
  const result = await sandbox.run(['node', '--version']);
  return c.json({
    exitCode: result.exitCode,
    stdout: new TextDecoder().decode(result.stdout),
  });
});

An app with this route and no sandbox.image gets a default image that does not exist:

1.13.1 This PR
vp build Exits 0 and records node_modules/void/dist/sandbox.Dockerfile, which does not exist Records node_modules/void/sandbox.Dockerfile, the file the package ships
vp dev Stops before it serves anything: ENOENT: no such file or directory, open '<app>/node_modules/void/dist/sandbox.Dockerfile' Builds the image and serves. The route answers {"exitCode":0,"stdout":"v26.12.1\n"}
Image build of void deploy --platform cloudflare docker build cannot read the Dockerfile, and the deploy says "Sandbox image preparation failed. Start Docker and retry the deployment." while Docker is running Builds the image

main has the same code as 1.13.1 here. A deploy to a Void platform takes a different path: its manifest carries sandbox.platformImage, not the Dockerfile.

getDefaultSandboxImage() finds the file relative to the void/sandbox entry, as ../../sandbox.Dockerfile. 38db82c (#841), first released in 1.10.0, moved that entry from dist/runtime/sandbox.mjs to dist/runtime/sandbox/index.mjs, so the same relative URL now ends in dist/. The default-image test checked only the file name.

The deploy's message hid the cause. Every failed docker build of a Sandbox image got the "Start Docker" advice, also while Docker was running:

docker build main This PR
Fails while Docker is running, for example on a missing Dockerfile "Sandbox image preparation failed. Start Docker and retry the deployment." "Sandbox image preparation failed: docker build exited with code 1 for <Dockerfile>. See the Docker output above."
Fails because the daemon is not running The same "Start Docker" message Unchanged
Is stopped by a signal The same "Start Docker" message "Sandbox image preparation failed: docker build was stopped by SIGTERM for <Dockerfile>."
Cannot start, because the Docker CLI is missing spawn docker ENOENT "Sandbox image preparation failed: the Docker CLI could not be started (spawn docker ENOENT). Check that Docker is installed and retry the deployment."

Fix

  • Default image (first commit): package.json names the Dockerfile in the package's private imports, as #self/sandbox.Dockerfile, and getDefaultSandboxImage() resolves it from there. The path no longer depends on where a built module sits in dist/, and the packed checks already verify that every imports target is in the tarball. The file stays at the package root, so its path in an installed package does not change.
  • Deploy message (second and third commits): after a failed build, the deploy asks the daemon with docker info. "Start Docker" stays for a daemon that does not answer, when docker info exits with a non-zero code. A build that succeeds runs no extra command.
  • docker info gets 5 seconds, so a daemon that accepts the connection and never answers cannot keep back the report. When the check does not finish in time, or cannot run, the deploy reports the build failure, whose cause Docker has printed above.
  • At that deadline the deploy kills only the CLI process. docker info starts the CLI plugins just to read their metadata, before it asks the daemon, so it has no child process while it waits.

Tests

  • packages/void/test/unit/config.test.ts: the default-image case reads the resolved path and compares it with the packaged Dockerfile. With main's sandbox/config.ts it fails with ENOENT for packages/void/dist/sandbox.Dockerfile.
  • packages/void/test/integration/kitchen-sink-build.test.ts: the playground sets no sandbox.image, and the build case checks that the Dockerfile recorded in dist/ssr/wrangler.json exists. With main's sandbox/config.ts it fails.
  • packages/void/test/unit/container-image.test.ts (new, 6 cases): buildContainerImage() with a stand-in Docker CLI.
    • A build that succeeds: no daemon check, and dispose() removes the local tag.
    • A build that fails while the daemon answers, and one while it does not.
    • A docker info that hangs, with the deadline reached through fake timers.
    • A build that a signal stops, and a CLI that cannot be started.

5 of the 6 container-image cases fail with main's container-image.ts; the first one checks what main already does. The file is skipped on Windows, which does not launch the stand-in script by path.

Verification

  • vpr test:all: builds the packages and playgrounds, runs vp check and check:types, and runs the platform, unit and integration groups; 269/269 tasks pass.
  • node .github/scripts/packed-consumer.mjs passes for npm and pnpm. The void tarball contains sandbox.Dockerfile.
  • By hand, in a new static Vue starter (void init, Vite+) with the route above, no sandbox key in void.config.ts, and Docker 29.8.2 running:
    • void 1.13.1 from npm: vp build and vp dev as in the 1.13.1 column.
    • The packed build of this branch, installed with npm and with pnpm: vp build and vp dev as in the "This PR" column. In the pnpm install, the recorded path is under node_modules/.pnpm/ and exists.
  • By hand, buildContainerImage(), which the deploy runs for each recorded Dockerfile, with the real Docker CLI (29.8.2):
    • main's version, with a Dockerfile that does not exist: the "Start Docker" message, while docker info answers.
    • This branch, with the Dockerfile that the npm app's build records: it builds void-sandbox-build:<uuid> for linux/amd64, and dispose() removes the tag.
    • A Dockerfile that does not exist: the "exited with code 1" message.
    • DOCKER_HOST set to a socket that does not exist: the "Start Docker" message.
    • A failed build, with docker info sent to a socket that accepts connections and never answers: the "exited with code 1" message after 5 seconds, and no Docker process is left.
    • A CLI path that does not exist: the "could not be started" message.
  • By hand, docker info (29.8.2) against that socket: it runs each plugin's metadata command when it starts, has no child process while it waits, and leaves none when the CLI is killed.
  • Not run: void deploy --platform cloudflare from start to end, a deploy to a Void platform, VOID_PACKED_SUITE=full, a build that a signal stops outside the unit test, and Windows.

🤖 Generated with Claude Code

morinokami and others added 3 commits December 6, 2026 12:01
Since 1.10.0, an app that imports `void/sandbox` and sets no
`sandbox.image` gets a default image that does not exist,
`node_modules/void/dist/sandbox.Dockerfile`. The package ships the file
at its root. `vp build` records the missing path, and `vp dev` stops
before it serves anything:

    Error: ENOENT: no such file or directory, open
    '<app>/node_modules/void/dist/sandbox.Dockerfile'

`void deploy --platform cloudflare` fails at `docker build` and says
"Sandbox image preparation failed. Start Docker and retry the
deployment." while Docker is running. 1.9.1 works. Deploys to a managed
platform are not affected: they never build the Dockerfile.

`getDefaultSandboxImage()` finds the file relative to the `void/sandbox`
entry, as `../../sandbox.Dockerfile`. 38db82c (voidzero-dev#841) moved that entry
from `dist/runtime/sandbox.mjs` to `dist/runtime/sandbox/index.mjs`, so
the same relative URL now ends in `dist/`.

## Fix

Name the Dockerfile in the package's private `imports`, as
`#self/sandbox.Dockerfile`, and resolve it from there. The path no longer
depends on where a built module sits in `dist/`, and the packed checks
already verify that every `imports` target is in the tarball.

The file stays at the package root, so a config that works around the
bug with `sandbox.image: './node_modules/void/sandbox.Dockerfile'` keeps
working.

## Tests

The default-image test checked only the file name. It now reads the
resolved path and compares it with the packaged Dockerfile. The
kitchen-sink build test checks that the Dockerfile recorded in
`dist/ssr/wrangler.json` exists. Both fail without the fix.

## Verification

- By hand, with the packed build installed in a new starter and Docker
  running: `vp build` records `node_modules/void/sandbox.Dockerfile`,
  `vp dev` builds the image, and the "Run a command" route of the
  Sandboxes guide answers `{"exitCode":0,"stdout":"v26.12.1\n"}`.
  `void deploy --platform cloudflare`, against a local stand-in for the
  Cloudflare API, builds the image and goes on to the Worker upload. The
  same steps on the published 1.13.1 fail as described above.
- `node .github/scripts/packed-consumer.mjs` passes for npm and pnpm,
  and with `VOID_PACKED_SUITE=full`. A pnpm install resolves the default
  image to an existing file too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`void deploy --platform cloudflare` answered every failed `docker build`
of a Sandbox image with "Sandbox image preparation failed. Start Docker
and retry the deployment.". That was also the answer while Docker was
running and the build itself failed, for example on a missing Dockerfile
or a failing step. When the Docker CLI could not be started at all, the
deploy printed the raw spawn error instead (`spawn docker ENOENT`).

## Fix

After a failed build, ask the daemon with `docker info`. When it
answers, name the failure: `docker build`'s exit code and the Dockerfile,
with a pointer to Docker's output above. Keep the "Start Docker" advice
for the cases it fits: the daemon does not answer, or the CLI cannot be
started. A build that succeeds runs no extra command.

## Tests

`container-image.test.ts` runs `buildContainerImage()` with a stand-in
Docker CLI: a build that succeeds, a build that fails while the daemon
answers, a daemon that does not answer, and a CLI that cannot be
started.

## Verification

- `vpr test:all` passes on this branch: 267/267 tasks, 19,660 tests pass,
  35 skipped.
- By hand, `void deploy --platform cloudflare` against a local stand-in
  for the Cloudflare API, with Docker running and a Dockerfile whose
  `RUN` step fails:

      Sandbox image preparation failed: `docker build` exited with code 1
      for <app>/Dockerfile.broken. See the Docker output above.

  With `DOCKER_HOST` set to a socket that does not exist, and with a
  Docker CLI that cannot be started, it prints the "Start Docker"
  message.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The previous commit reports a failed `docker build` of a Sandbox image
as a build failure while Docker is running. `void deploy --platform
cloudflare` still said "Sandbox image preparation failed. Start Docker
and retry the deployment." in two cases that starting Docker does not
fix: the Docker CLI could not be started, for example because Docker is
not installed, and a signal stopped the build.

The check of the daemon also had no time limit. After a failed build
the deploy runs `docker info` to tell a failed build from a daemon that
is not running. A daemon that accepts the connection and never answers
kept the deploy waiting, without a report of the failed build.

## Fix

- When the CLI cannot be started, name the cause: "the Docker CLI could
  not be started (spawn docker ENOENT). Check that Docker is installed
  and retry the deployment."
- When a signal stopped the build, name the signal and do not ask the
  daemon: "`docker build` was stopped by SIGTERM for <Dockerfile>."
- Give `docker info` 5 seconds. When it does not finish in time, or
  cannot run, report the build failure: Docker has printed the cause
  above. "Start Docker" stays for the daemon that is known not to
  answer, when `docker info` exits with a non-zero code.

At the deadline the deploy kills only the CLI process. `docker info`
starts the CLI plugins just to read their metadata, before it asks the
daemon, so it has no child process while it waits. Checked with Docker
29.8.2 against a socket that accepts connections and never answers.

## Tests

`container-image.test.ts` adds a `docker info` that hangs, with the
deadline reached through fake timers, and a build that a signal stops.
The case of a CLI that cannot be started expects the new message.

## Verification

- `vpr test:all` passes on this branch: 267/267 tasks, 19,662 tests
  pass, 35 skipped.
- By hand, `buildContainerImage()` with the real Docker CLI (29.8.2).
  With Docker running and no Dockerfile:

      Sandbox image preparation failed: `docker build` exited with code 1
      for <dir>/Dockerfile. See the Docker output above.

  With a failed build and `docker info` sent to a socket that never
  answers, the same report comes after 5 seconds, and no Docker process
  is left. With a CLI path that does not exist:

      Sandbox image preparation failed: the Docker CLI could not be
      started (spawn <path> ENOENT). Check that Docker is installed and
      retry the deployment.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@morinokami
morinokami requested a review from a team as a code owner December 6, 2026 03:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant